var Sequelize=require("sequelize");
var sequelize = new Sequelize('cms', 'root', '', {
  host: '192.168.3.24',
  dialect: 'mysql',

  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },

  // SQLite only
  storage: 'path/to/database.sqlite'
});

// Or you can simply use a connection uri
//var sequelize = new Sequelize('postgres://user:pass@example.com:5432/dbname');
//要定义模式和表之间的映射，使用define方法。那么Sequelize会自动添加的属性createdAt，并updatedAt给它
//行业标准/合作商户
var Article = sequelize.define('article', {
  title: {//标题
    type: Sequelize.STRING,
    field: 'title' // Will result in an attribute that is firstName when user facing but first_name in the database
  },
  subtitle: {//副标题
    type: Sequelize.STRING
  },
  summary: {//摘要
    type: Sequelize.STRING
  },
  date: {//日期
    type: Sequelize.STRING
  },
  content: {//内容
    type: Sequelize.STRING
  },
  imgUrl: {//图片链接
    type: Sequelize.STRING
  },
  source: {//来源
    type: Sequelize.STRING
  },categoryId
  author: {//作者
    type: Sequelize.STRING
  },
  categoryId: {//分类
    type: Sequelize.STRING
  }
}, {
  freezeTableName: true // Model tableName will be the same as the model name
});
//force:true  重建之前删除表
/*
Article.sync({force: false}).then(function () {
  // Table created
  return Article.create({
    firstName: 'John',
    lastName: 'Hancock'
  });
});

//查找第一条
Article.findOne().then(function (article) {
    console.log(article.get('firstName'));
});



//根据某个字段精确查找
Article.findOne({where:{firstName:'John'}}).then(function (article) {
 //   console.log(article);
});

//更改
Article.update({
  firstName:'JohnUpdate'
},{where:{
  firstName:'John'
}});
//根据id查找
Article.findById(1).then(function (article) {
    console.log(article.get('firstName'));
});

//删除
// Article.destroy({
//   where:{
//     id:1
//   }
// }).then(function(user){
//     console.log("删除成功");
// })
*/


module.exports = Article; 